import Vue from 'vue'

import 'normalize.css/normalize.css'// A modern alternative to CSS resets

import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css
import '@/styles/dynamic.less'

import App from './App'
import router from './router'
import store from './store'
import constantData from './constant'

import './icons' // icon
import './error-log'// error log
import './permission' // permission control

import * as filters from './filters' // global filters

import 'babel-polyfill' // 解决IE空白问题

import $utils from './utils' // 导入工具包
import $pt from './utils/platform'
import mixin from './mixin'
import formatNum from '@/directive/formatNum/formatNum'
import { VueJsonp } from 'vue-jsonp'
Vue.use(VueJsonp)

// 可以自己封装组件，以下是示例，使用：this.$getXXX
// import { getXXX } from '@/utils/getXXX'
// Object.defineProperty(Vue.prototype, '$getXXX', { value: getXXX() })

// 修改 el-dialog 默认点击遮照为不关闭
Element.Dialog.props.closeOnClickModal.default = false
Vue.use(Element, {
  size: 'medium' // set element-ui default size
})

// 混入
Vue.mixin(mixin)
Vue.directive('formatNum', formatNum)
// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

// 全局方法
Vue.prototype.$utils = $utils
Vue.prototype.$pt = $pt
Vue.prototype.resetForm = $utils.resetForm
Vue.prototype.constant = constantData

import SlideVerify from 'vue-monoplasty-slide-verify'
Vue.use(SlideVerify)

import vueSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(vueSwiper)

// 注册全局组件
Vue.component('icon', { template: '<div></div>' })

Vue.prototype.msgError = function(msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: 'error'
  })
}

Vue.prototype.msgInfo = function(msg) {
  this.$message.info(msg)
}

Vue.prototype.msgSuccess = function(msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: 'success'
  })
}
// 分页控件
import Pagination from '@/components/Pagination'
// 全局组件挂载 组件可以直接<pagination/>使用
Vue.component('Pagination', Pagination)

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
const bus = new Vue()
Vue.prototype.$bus = bus
